package thread;

import java.util.Scanner;

//中断程序 终止
public class Demo7 {
    public static boolean flg = true;//lambda变量捕获需要final / 事实final
    public static void main(String[] args) {
        Thread thread = new Thread(() -> {
            while (flg) {
                System.out.println("hello thread");
                try {
                    Thread.sleep(100_000);//终止了但还是处于阻塞状态 没有立即结束进程
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });

        thread.start();
        Scanner scanner = new Scanner(System.in);
        System.out.println("输入1则终止程序");
        int n = scanner.nextInt();
        if (n == 1) flg = false;
        jie();
    }
}
